using System;
using EPiServer.Common;
using EPiServer.Common.Queries;
using EPiServer.Common.Rating;
using EPiServer.Common.Security;

namespace EPiAbstractions.Common.Rating
{
    public class RatingHandlerFacade : IRatingHandlerFacade
    {
        private static RatingHandlerFacade _instance;

        public static RatingHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new RatingHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IRatingHandlerFacade Members

        public virtual RatableEntityCollection GetRatedItems(Double rating, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(rating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Type type, Double rating, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(type, rating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                             out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Type type, Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                             out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(type, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(SiteCollection sites, NullValueAction siteNullAction, Double rating, Int32 page,
                                                             Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(sites, siteNullAction, rating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Type type, SiteCollection sites, NullValueAction siteNullAction, Double rating,
                                                             Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(type, sites, siteNullAction, rating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(SiteCollection sites, NullValueAction siteNullAction, Double minRating,
                                                             Double maxRating, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(sites, siteNullAction, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Type type, SiteCollection sites, Double minRating, Double maxRating, Int32 page,
                                                             Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(type, sites, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatableEntityCollection GetRatedItems(Type type, SiteCollection sites, NullValueAction siteNullAction,
                                                             Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                             out Int32 totalItems)
        {
            return RatingHandler.GetRatedItems(type, sites, siteNullAction, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual IRating GetRating(IRatableEntity ratable, IAuthor author)
        {
            return RatingHandler.GetRating(ratable, author);
        }

        public virtual RatingCollection GetRatings(IAuthor author, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(author, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(Type type, IAuthor author, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(type, author, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IAuthor author, Double rating, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(author, rating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(Type type, IAuthor author, Double rating, Int32 page, Int32 pageSize,
                                                   out Int32 totalItems)
        {
            return RatingHandler.GetRatings(type, author, rating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IAuthor author, Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                   out Int32 totalItems)
        {
            return RatingHandler.GetRatings(author, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(Type type, IAuthor author, Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                   out Int32 totalItems)
        {
            return RatingHandler.GetRatings(type, author, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, IAuthor author, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, author, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, Double rating, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, rating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, IAuthor author, Double rating, Int32 page, Int32 pageSize,
                                                   out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, author, rating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, Double minRating, Double maxRating, Int32 page, Int32 pageSize,
                                                   out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetRatings(IRatableEntity ratable, IAuthor author, Double minRating, Double maxRating, Int32 page,
                                                   Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetRatings(ratable, author, minRating, maxRating, page, pageSize, out totalItems);
        }

        public virtual PopularRatableEntityCollection GetMostPopularItems(Int32 minimumVotesRequired, Int32 page, Int32 pageSize)
        {
            return RatingHandler.GetMostPopularItems(minimumVotesRequired, page, pageSize);
        }

        public virtual PopularRatableEntityCollection GetMostPopularItems(Type objectType, Int32 minimumVotesRequired, Int32 page,
                                                                          Int32 pageSize)
        {
            return RatingHandler.GetMostPopularItems(objectType, minimumVotesRequired, page, pageSize);
        }

        public virtual PopularRatableEntityCollection GetMostPopularItems(Type objectType, Int32 minimumVotesRequired, Int32 page,
                                                                          Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetMostPopularItems(objectType, minimumVotesRequired, page, pageSize, out totalItems);
        }

        public virtual PopularRatableEntityCollection GetMostPopularItems(Type objectType, Int32 minimumVotesRequired, Int32 page,
                                                                          Int32 pageSize, TimeSpan? explicitCacheExpiration,
                                                                          out Int32 totalItems)
        {
            return RatingHandler.GetMostPopularItems(objectType, minimumVotesRequired, page, pageSize, explicitCacheExpiration,
                                                     out totalItems);
        }

        public virtual RatingCollection GetUsersRatedItems(UserCollection users, Int32 page, Int32 pageSize)
        {
            return RatingHandler.GetUsersRatedItems(users, page, pageSize);
        }

        public virtual RatingCollection GetUsersRatedItems(UserCollection users, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return RatingHandler.GetUsersRatedItems(users, page, pageSize, out totalItems);
        }

        public virtual RatingCollection GetUsersRatedItems(UserCollection users, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                           Type objectType)
        {
            return RatingHandler.GetUsersRatedItems(users, page, pageSize, out totalItems, objectType);
        }

        public virtual Boolean HasRated(IRatableEntity ratable, IAuthor author)
        {
            return RatingHandler.HasRated(ratable, author);
        }

        public virtual void Rate(IRating rating)
        {
            RatingHandler.Rate(rating);
        }

        public virtual void GetRatableEntityValues(IRatableEntity ratable, out Boolean isRatable, out Int32 numRatings,
                                                   out Double sumRatings, out ISite site)
        {
            RatingHandler.GetRatableEntityValues(ratable, out isRatable, out numRatings, out sumRatings, out site);
        }

        public virtual IRating GetRating(Int32 id)
        {
            return RatingHandler.GetRating(id);
        }

        #endregion
    }
}